package com.jf3q.front.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jf3q.common.domain.EduTeacher;
import com.jf3q.common.vo.ResultVo;
import com.jf3q.front.entity.Teacher;
import com.jf3q.front.service.TeacherService;
import com.jf3q.front.vo.MyPageVo;
import io.swagger.v3.oas.annotations.Operation;
import jakarta.annotation.Resource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/eduservice/teacherfront")
public class TeacherController {

    @Autowired
    TeacherService teacherService;

    @Resource
    private RedisTemplate<Object, Object> redisTemplate;


    @GetMapping("/getHotTeacher")
    @Operation(summary = "查询名师大咖")
    public ResultVo HotTeacher(){
        List<Teacher> hotEduTeacher = teacherService.getHotEduTeacher();
        String key = "teacher";
        Boolean bool = redisTemplate.hasKey(key);
        if (bool){
            redisTemplate.opsForList().set(key, 0, hotEduTeacher);
        }else {
            redisTemplate.opsForList().leftPushAll(key, hotEduTeacher);
        }
        Object redisTeacherList = redisTemplate.opsForList().index(key,0);
        return ResultVo.success("查询名师大咖",redisTeacherList);
    }
    @PostMapping("/getTeacherFrontList/{page}/{limit}")
    public ResultVo getTeacherFrontList(@PathVariable Integer page, @PathVariable Integer limit) {
        Page<Teacher> getpage = teacherService.page(new Page<>(page, limit));
        MyPageVo pageVo = new MyPageVo();
        pageVo.setPage(getpage);
        pageVo.setHasPrevious(getpage.hasPrevious());
        pageVo.setHasNext(getpage.hasNext());
        return ResultVo.success("查询所有讲师", pageVo);
    }

    @GetMapping("/getTeacherFrontInfo/{id}")
    public ResultVo getTeacherFrontInfo(@PathVariable String id) {
        Teacher teacher = teacherService.cha(id);
        return ResultVo.success("查询单个讲师", teacher);
    }


}
